import 'package:dio/dio.dart';
import 'package:flutter_app/http/http_utils.dart';
import 'package:flutter_app/utils.dart';

class ATCHttpUtils {
  static const String APP_KEY = "com.che168.www";
  static get(String url, {data, options, cancelToken}) {}
  static Future<Map<String, dynamic>> post(String url,
      {data, options, cancelToken}) {
    FormData formData = data;
    formData.add("_appid", "atc.android");
    formData.add("channelid", "csy");
    formData.add("appversion", "1.9.33");
    formData.add("udid", "uQwMXYYmTz8d4JWcp6SSWtSiPmgSQsTCoKv3/DlnYpbyanPe4Yr34g==");

    var sortedKeys = formData.keys.toList()..sort();
    StringBuffer signStr = StringBuffer();
    signStr.write(APP_KEY);
    for (var key in sortedKeys) {
      signStr.write(key);
      signStr.write(formData[key]);
    }
    signStr.write(APP_KEY);
    formData.add("_sign", Utils.md5(signStr.toString()).toUpperCase());

    return HttpUtils()
        .post(url, data: formData, options: options, cancelToken: cancelToken);
  }
}
